package fpt.myFileHandler;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * TXTHandler
 * 
 * r25
 * 
 * 12 March 2010
 * 
 * The TXTHandler class processes input files that are normal text
 * files. There is no extra processing required.
 * @author Daniel De Guzman
 *
 */
public class TXTHandler extends Handler {
	private String[] processedInput;
	private int k;
	private int vCount;
	private String[] vInfoArray;
	private String error;

	/**
	 * Constructor
	 * @param in - input file
	 * @throws IOException
	 */
	public TXTHandler(FileReader in) throws IOException{
		this.processedInput = this.processInput(in);
		this.k = Functions.getValue(processedInput, 0);
		this.vCount = Functions.getValue(processedInput, 1);
		this.vInfoArray = new String[processedInput.length-2];
		System.arraycopy(processedInput, 2, vInfoArray, 0, vInfoArray.length);
		this.error = "";
	}
	
	/**
	 * Takes input as-is and returns a string array
	 * @param in - TXT file
	 * @return String[] - Array containing data needed
	 * @throws IOException
	 */
	String [] processInput(FileReader in) throws IOException{
		BufferedReader br = new BufferedReader(in);
		String temp = "";
		List<String> output = new ArrayList<String>();
		while ((temp = br.readLine()) != null){
			output.add(temp);
		}
		return output.toArray(new String[output.size()]);
	}

	// Setters and Getters
	
	public String[] getProcessedInput() {
		return processedInput;
	}

	public void setProcessedInput(String[] processedInput) {
		this.processedInput = processedInput;
	}

	public int getK() {
		return k;
	}

	public void setK(int k) {
		this.k = k;
	}

	public int getvCount() {
		return vCount;
	}

	public void setvCount(int vCount) {
		this.vCount = vCount;
	}

	public String[] getvInfoArray() {
		return vInfoArray;
	}

	public void setvInfoArray(String[] vInfo) {
		this.vInfoArray = vInfo;
	}

	public String getError() {
		return error;
	}

	public void setError(String error) {
		this.error = error;
	}
}
